from django.db import models
from django.conf import settings


# Create your models here.
class Resource(models.Model):
    # 基础表
    resourceName = models.CharField(max_length=20, null=True, verbose_name='资源名')
    resourceUrl = models.FileField(upload_to='upload_file', verbose_name='资源路径')
    resourceSize = models.IntegerField(null=True, verbose_name='资源大小')
    remark = models.TextField(null=True, verbose_name='资源描述')
    keyword = models.CharField(max_length=128, null=True, verbose_name='关键词')
    resourceType = models.CharField(max_length=20, verbose_name='关键字')
    type = models.IntegerField(verbose_name='资源类别')
    starlevel = models.IntegerField(verbose_name='资源评价几星')
    score = models.IntegerField(null=True, verbose_name='资源分')
    userId = models.IntegerField(null=True, verbose_name='用户id')
    status = models.IntegerField(default=0, verbose_name='资源是否审核状态')
    delFlag = models.IntegerField(default=0, verbose_name='资源是否删除')
    Create_time = models.DateTimeField(verbose_name='创建时间')
    Update_time = models.DateTimeField(verbose_name='更新时间')


class ResourceExtends(models.Model):
    readNum = models.IntegerField(verbose_name='浏览量')
    downloadNum = models.IntegerField(verbose_name='下载量')
    scNum = models.IntegerField(verbose_name='收藏量')
    Create_time = models.DateTimeField(verbose_name='创建时间')
    Update_time = models.DateTimeField(verbose_name='更新时间')
    resource = models.ForeignKey(Resource, on_delete=models.CASCADE)

    class Meta:
        db_table = 'resource_ex'


class FileInfo(models.Model):
    fileName = models.CharField(max_length=32)
    fileUrl = models.FileField(upload_to='upload_file')


class User(models.Model):
    userName = models.CharField(max_length=20, verbose_name='用户名')
    password = models.CharField(max_length=20, verbose_name='用户密码')
    phone = models.CharField(max_length=20, verbose_name='电话')
    email = models.EmailField(verbose_name='邮件')
    gender = models.BooleanField(default=True)
    age = models.IntegerField(null=True)
    actorurl = models.FileField(null=True)
    nickname = models.CharField(max_length=20, null=True)
    usertype = models.IntegerField(default=0)
    status = models.IntegerField(default=0)
    derflag = models.BooleanField(default=False)
    create_time = models.DateTimeField()
    update_time = models.DateTimeField()
    realName = models.CharField(max_length=20, null=True)
    birthday = models.DateTimeField(null=True)


# 通知表
class Notice(models.Model):
    Userid = models.IntegerField(verbose_name='用户id')
    Type = models.CharField(max_length=255, verbose_name='类型')
    Noticetype = models.CharField(max_length=255, verbose_name='消息类型')
    Content = models.CharField(max_length=255, verbose_name='内容')
    Create_time = models.DateTimeField(verbose_name='通知时间')


# 私信表
class Private_letter(models.Model):
    Userid = models.IntegerField(verbose_name='用户id')
    Contactid = models.IntegerField(verbose_name='接收id')
    Message = models.CharField(max_length=255, verbose_name='消息详情')
    Create_time = models.DateTimeField(verbose_name='创建时间')
    Update_time = models.DateTimeField(verbose_name='更新时间')


# 黑名单表
class Black_user(models.Model):
    user = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE, related_name='blacklists')
    black_user = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE, related_name='blacklisted_by')

    class Meta:
        unique_together = ('user', 'black_user')
